package cn.fay.chapter18;

import java.io.File;
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
/**
 * 可以看到，通过映射，可以显著的提供啊性能
 * @author emellend
 *
 */
public class LargeMappedFiles {

	public static void main(String[] args) throws Exception {
		int length=0x8ffffff;
		MappedByteBuffer out = new RandomAccessFile(new File("data2.txt").getAbsoluteFile(), "rw").getChannel().
			map(FileChannel.MapMode.READ_WRITE, 0, length);
		for(int i=0;i<length;i++){
			out.put((byte)'x');
		}
		System.out.println("Finished writing");
		for (int i = length/2; i < length/2+6; i++) {
			System.out.println((char)out.get(i));
		}
	}
}
